<?php

namespace app\adminapi\controller\system;

use app\adminapi\service\SysMenuService;
use app\adminapi\validate\SystemMenuValidate;
use app\common\controller\BaseAdminController;

class SystemMenuController extends BaseAdminController
{
    public array $notNeedLogin = [];

    public function list()
    {
        $result = (new SysMenuService())->getSysMenuListWithoutAction();
        return app('json')->successWithData($result);
    }

    public function listAll()
    {
        $result = (new SysMenuService())->getSysMenuAllList();
        return app('json')->successWithData($result);
    }

    /**
     * @title  新增菜单
     * @businessType    INSERT
     * @return void
     */
    public function insert()
    {
        $params = (new SystemMenuValidate())->post()->goCheck('insert');
        (new SysMenuService())->addSysMenu($params);
        return app('json')->success();
    }

    /**
     * @title   删除菜单
     * @businessType    DELETE
     * @return mixed
     */
    public function delete()
    {
        $params = (new SystemMenuValidate())->delete()->goCheck('delete');
        $result = (new SysMenuService())->deleteSysMenu($params['menuId']);
        return app('json')->successWithData($result);
    }

    public function query()
    {
        $params = (new SystemMenuValidate())->get()->goCheck('query');
        $result = (new SysMenuService())->getSysMenu($params['menuId']);
        return app('json')->successWithData($result);
    }

    /**
     * @title   更新菜单
     * @businessType    UPDATE
     * @return mixed
     */
    public function update()
    {
        $params = (new SystemMenuValidate())->put()->goCheck('update');
        $result = (new SysMenuService())->updateSysMenu($params);
        return app('json')->successWithData($result);
    }

    public function listAllActionByMenuId()
    {
        $params = (new SystemMenuValidate())->get()->goCheck('query');
        $result = (new SysMenuService())->getAllActionByMenuId($params['menuId']);
        return app('json')->successWithData($result);
    }
}